package com.chenchao.designer.prototype;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/2/20 23:27
 * @file : javaSE.com.chenchao.designer.prototype.test01.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
public class Test01 {
    public static void main(String[] args) {
        Plane plane = new Plane();
        Plane o =(Plane) plane.cloneObject();
        System.out.println("plane:"+plane.getName()+","+plane.getType());
        System.out.println("o:"+o.getName()+","+o.getType());
    }
}

/**
 * 克隆接口
 */
interface Photo extends Cloneable{
    /**
     * 对象克隆
     * @return 克隆的对象
     */
    Object cloneObject();
}
class Plane implements Photo {
    private String name;
    private String type;
    public Plane() {
        name="name"+Math.random();
        type="type"+Math.random();
    }

    public Plane(String name, String type) {
        this.name = name;
        this.type = type;
    }

    public Plane(Plane plane){
        this(plane.name,plane.type);
    }
    @Override
    public Object cloneObject() {
        /*内部this可以访问到私有成员与属性*/
        return new Plane(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
